<template>
  <el-container class="home-container">
    <el-header>
      <div>
        <img src="../assets/logo.png" alt="new system" />
        <span>新闻推荐系统</span>
      </div>
      <el-button class="lg-button" type="info" @click="logout"
        >log out</el-button
      >
    </el-header>
    <el-container>
    <el-aside :width="iscollapse ? '64px':'200px' ">
      <div class="toggle-button" @click="toggle">|||</div>
        <el-menu :default-active="activePath" background-color="#333744" text-color="#fff" active-text-color="#409EFF" unique-opened :collapse-transition='false' :collapse='iscollapse' router>

          <el-submenu :index="item.id+''" :key="item.id" v-for="item in lists">
            <template slot="title">
              <i :class="iconobj[item.id]"></i>
              <span>{{item.authName}}</span>
            </template>

            <el-menu-item :index="'/'+tem.path" :key="tem.id" v-for="tem in item.children" @click="onactive('/'+tem.path)">
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{tem.authName}}</span>
              </template>
            </el-menu-item>

          </el-submenu>
        </el-menu>
    </el-aside>
      <el-main><router-view></router-view></el-main>
      
    </el-container>
  </el-container>
</template>
<script>
export default {
  data(){
    return {
      lists:[],
      iconobj:{
        '125':'iconfont icon-user',
        '103':'iconfont icon-tijikongjian',
        '101':'iconfont icon-shangpin',
        '102':'iconfont icon-danju',
        '145':'iconfont icon-baobiao'
      },
      iscollapse:false,
      activePath:'/users'
    }
  },
  created(){
    this.getListApi()
    this.activePath=window.sessionStorage.getItem('activePath')
  },
  methods: {
    logout: function () {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    getListApi:async function(){
      const {data:res}=await this.$http.get('menus')
      console.log(res)
      if(res.meta.status!=200) return this.message.error(res.meta.msg);
      this.lists=res.data
      
    },
    toggle(){
      this.iscollapse=!this.iscollapse
    },
    onactive(path){
      window.sessionStorage.activePath=path
          this.activePath=window.sessionStorage.getItem('activePath')

      // this.$router.push('/home'+path)
    }
  },
}
</script>
<style lang="less" scoped>
.el-header {
  display: flex;
  justify-content: space-between;
  background-color: #373d41;
  color: antiquewhite;
  font-size: 20px;
  padding-left: 0px;
  align-items: center;
  > div {
    display: flex;
    align-items: center;
  }
}
.el-aside {
  background-color: #333744;
  .el-menu{
    border-right: 0px;
  }
}
.el-main {
  background-color: #eaedf1;
}
.home-container {
  height: 100%;
}
.iconfont{
  margin-right: 10px;
}
.toggle-button{
  background-color: #4a5064;
  font-size: 10px;
  color: #fff;
  text-align: center;
  line-height: 24px;
  cursor: pointer;
  letter-spacing: 0.2em;
  // vertical-align: middle;

}
</style>